package net.wwang.open.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @author WangWei
 * @date 2020/8/11
 */

@Configuration
@EnableSwagger2
public class SwaggerConfig {
	public static final String VERSION = "1.0.0";

	@Bean
	public Docket UserApi() {
		return new Docket(DocumentationType.SWAGGER_2)
				.apiInfo(userApiInfo())
				.select()
				.apis(RequestHandlerSelectors.basePackage("net.wwang.open.server.controller.user"))
				.paths(PathSelectors.any())
				.build()
				.groupName("user");
	}

	private ApiInfo userApiInfo() {
		return new ApiInfoBuilder()
				.title("SecZone Open Docs")
				.description("用户接口服务")
				.contact(new Contact("SecZone", "http://www.seczone.cn", "codewwang@163.com"))
				.version(VERSION)
				.build();
	}

	@Bean
	public Docket AdminApi() {
		return new Docket(DocumentationType.SWAGGER_2)
				.apiInfo(adminApiInfo())
				.select()
				.apis(RequestHandlerSelectors.basePackage("net.wwang.open.server.controller.admin"))
				.paths(PathSelectors.any())
				.build()
				.groupName("admin");
	}

	private ApiInfo adminApiInfo() {
		return new ApiInfoBuilder()
				.title("SecZone Open Docs")
				.description("管理员接口服务")
				.contact(new Contact("SecZone", "http://www.seczone.cn", "codewwang@163.com"))
				.version(VERSION)
				.build();
	}

	@Bean
	public Docket PortalApi() {
		return new Docket(DocumentationType.SWAGGER_2)
				.apiInfo(potalApiInfo())
				.select()
				.apis(RequestHandlerSelectors.basePackage("net.wwang.open.server.controller.potal"))
				.paths(PathSelectors.any())
				.build()
				.groupName("portal");
	}

	private ApiInfo potalApiInfo() {
		return new ApiInfoBuilder()
				.title("SecZone Open Docs")
				.description("文档展示接口服务")
				.contact(new Contact("SecZone", "http://www.seczone.cn", "codewwang@163.com"))
				.version(VERSION)
				.build();
	}

}
